package com.apkfuns.jsbridge.view.base;

import com.apkfuns.jsbridge.view.base.slice.BaseAbilitySlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.window.dialog.ToastDialog;
import ohos.location.Location;
import ohos.location.Locator;
import ohos.location.LocatorCallback;
import ohos.location.RequestParam;

public class BaseAbility extends Ability {

    private LocatorCallback locationListener;
    private Locator locator;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setMainRoute(BaseAbilitySlice.class.getName());
    }

    public void setMenu(String title, final Runnable r) {
        new ToastDialog(getContext())
                .setText("暂时不支持Menu")
                .show();

    }



    public Location getLocation(LocatorCallback listener) {


        if(locator==null){
            locationListener = listener;
            locator = new Locator(getContext());
        }

        RequestParam requestParam = new RequestParam(RequestParam.SCENE_DAILY_LIFE_SERVICE);

        locator.requestOnce(requestParam, locationListener);

        return locator.getCachedLocation();
    }


    @Override
    public void terminateAbility(int requestCode) {
        super.terminateAbility(requestCode);
        if (locator != null && locationListener != null) {
            locator.stopLocating(locationListener);
        }
    }
}
